import { checkUserisVip } from '/store/mutations'

Component({
  properties: {
    user: { type: null, value: null },
    topic: { type: null, value: null },
    size: { type: String, value: '' },
    noLink: { type: Boolean, value: false },
    verify: { type: Boolean, value: false },
  },
  data: {
    avatarSrc: '',
    shape: 'circle',
    id: 0,
    defultAvatar: '',
    position: '',
    isVip: false,
  },
  observers: {
    user(user: DomoUser) {
      if (!user || !user.id) {
        return
      }
      const avatarSrc = user.avatar
        ? typeof user.avatar === 'string'
          ? user.avatar
          : user.avatar.url
        : ''
      const defultAvatar = 'https://houdong.ecoac.cn/images/avatar.png'

      this.setData({
        defultAvatar,
        avatarSrc,
        position: user.positions,
        shape: 'circle',
        id: user.id,
        isVip: checkUserisVip(user),
      })
    },
    topic(topic: DomoTopic) {
      if (!topic || !topic.id) {
        return
      }
      this.setData({
        avatarSrc: topic.logo.url,
        shape: 'fillet',
        id: topic.id,
      })
    },
  },
  methods: {
    viewUser() {
      // if (true || this.data.noLink) {
      //   wx.previewImage({
      //     current: this.data.avatarSrc,
      //     urls: [this.data.avatarSrc],
      //   })
      //   return
      // }
      // wx.navigateTo({
      //   url: this.data.topic
      //     ? `/pages/topic/detail/detail?topicId=${this.data.id}`
      //     : `/mine/homePage/homePage?id=${this.data.id}`,
      // })
    },
  },
})
